package com.samphanie.dries.properties;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.Min;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author ZSY
 * @createTime 2021/2/27 13:29
 */
@Getter
@Setter
@Validated
@Component
@ConfigurationProperties(prefix = "dries")
public class AppProperties {

    @Valid
    private JwtProperties jwt = new JwtProperties();

    @Valid
    private AliProperties ali = new AliProperties();

    private SmsProvider smsProvider = new SmsProvider();
    private EmailProvider emailProvider = new EmailProvider();

    @Getter
    @Setter
    public static class AliProperties {

        private String apiKey;
        private String apiSecret;

        private AliSms aliSms = new AliSms();

    }

    @Getter
    @Setter
    public static class AliSms {
        /*** 短信API产品名称（短信产品名固定，无需修改） */
        private String product = "Dysmsapi";
        private String regionId = "cn-hangzhou";
        private String version = "2017-05-25";
        private String action = "SendSms";
        /*** 短信API产品域名，接口地址固定，无需修改 */
        private String domain = "dysmsapi.aliyuncs.com";
        private String signName;
        private String accessKeyId;
        private String accessKeySecret;
        private Map<String, String> template = new HashMap<>();
    }

    @Getter
    @Setter
    public static class SmsProvider {
        private String name;
        private String apiUrl;
    }
    @Getter
    @Setter
    public static class EmailProvider {
        private String name;
        private String apiKey;
    }

    @Getter
    @Setter
    public static class JwtProperties {

        private String header = "Authorization"; // HTTP 报头的认证字段的 key

        private String prefix = "Bearer "; // HTTP 报头的认证字段的值的前缀

        @Min(5000L)
        private long accessTokenExpireTime = 60 * 1000L; // Access Token 过期时间

        @Min(3600000L)
        private long refreshTokenExpireTime = 30 * 24 * 3600 * 1000L; // Refresh Token 过期时间

        private String key;

        private String refreshKey;

    }

}
